/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    bool hasCycle(ListNode *head) {
        if(!head) return false;
        ListNode *kuai=head;
        ListNode *man=head;
        while(1){
            if(kuai->next){
            ListNode *node=kuai->next;
            man=man->next;
                if(node->next)
                    kuai=node->next;
                else return false;
            }
            else return false;
            if(kuai==man) {
                return true;
            }
        }
        return false;
    }
};